package com.flycent.fanbao.ui;

import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.annotation.view.ViewInject;

import cn.pedant.SweetAlert.SweetAlertDialog;

import com.flycent.fanbao.R;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class SweetAlertDialogActivity extends BackableTitleBarActivity{
	@ViewInject(id = R.id.basic_test ,click = "onClick") Button but1;
	@ViewInject(id = R.id.under_text_test ,click = "onClick") Button but2;
	@ViewInject(id = R.id.error_text_test ,click = "onClick") Button but3;
	@ViewInject(id = R.id.success_text_test ,click = "onClick") Button but4;
	@ViewInject(id = R.id.warning_confirm_test ,click = "onClick") Button but5;
	@ViewInject(id = R.id.warning_cancel_test ,click = "onClick") Button but6;
	@ViewInject(id = R.id.custom_img_test ,click = "onClick") Button but7;
	
	@Override
	protected void onCreate(Bundle savedInstance) {
		super.onCreate(savedInstance);
		setContentView(R.layout.activity_sweetalertdialog);
		FinalActivity.initInjectedView(this);
		getTitleBar().setTitle("dialog");
	}
	
	public void onClick(View v){
		// basic
		if( v == but1){
			new SweetAlertDialog(this).show();
		}
		//
		if( v == but2){
			   new SweetAlertDialog(this).setContentText("It's pretty, isn't it?")
               .show();
			
		}
		//error
		if( v == but3){
			  new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
              .setTitleText("Error...")
              .setContentText("Something went wrong!")
              .show();
		}
		//success
		if( v == but4){
			
			new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
            .setTitleText("Good job!")
            .setContentText("You clicked the button!")
            .show();
			
		}
		
		if( v == but5){
			
			 new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
             .setTitleText("Are you sure?")
             .setContentText("Won't be able to recover this file!")
             .setConfirmText("Yes,delete it!")
             .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
             @Override
             public void onClick(SweetAlertDialog sDialog) {
                 // reuse previous dialog instance
                 sDialog.setTitleText("Deleted!")
                         .setContentText("Your imaginary file has been deleted!")
                         .setConfirmText("OK")
                         .setConfirmClickListener(null)
                         .changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
             }
             })
             .show();
			
		}
		//
		if( v == but6){
			 new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
             .setTitleText("Are you sure?")
             .setContentText("Won't be able to recover this file!")
             .setCancelText("No,cancel plx!")
             .setConfirmText("Yes,delete it!")
             .showCancelButton(true)
             .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
                 @Override
                 public void onClick(SweetAlertDialog sDialog) {
                     // reuse previous dialog instance, keep widget user state, reset them if you need
                     sDialog.setTitleText("Cancelled!")
                             .setContentText("Your imaginary file is safe :)")
                             .setConfirmText("OK")
                             .showCancelButton(false)
                             .setCancelClickListener(null)
                             .setConfirmClickListener(null)
                             .changeAlertType(SweetAlertDialog.ERROR_TYPE);

                     // or you can new a SweetAlertDialog to show
                     sDialog.dismiss();
                     new SweetAlertDialog(SweetAlertDialogActivity.this, SweetAlertDialog.ERROR_TYPE)
                             .setTitleText("Cancelled!")
                             .setContentText("Your imaginary file is safe :)")
                             .setConfirmText("OK")
                             .show();
                 }
             })
             .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                 @Override
                 public void onClick(SweetAlertDialog sDialog) {
                     sDialog.setTitleText("Deleted!")
                             .setContentText("Your imaginary file has been deleted!")
                             .setConfirmText("OK")
                             .showCancelButton(false)
                             .setCancelClickListener(null)
                             .setConfirmClickListener(null)
                             .changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
                 }
             })
             .show();
			
		}
		//
		if( v == but7){
			 new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
             .setTitleText("Sweet!")
             .setContentText("Here's a custom image.")
             .setCustomImage(R.drawable.custom_img)
             .show();
		}
			
		
	}

}
